package org.frvi.goldspring.web.wicket.page;

import org.apache.wicket.IPageMap;
import org.apache.wicket.injection.web.InjectorHolder;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.frvi.goldspring.business.dao.GenericDao;

import java.lang.reflect.ParameterizedType;

/**
 * User: Frank
 * Date: Oct 13, 2009
 * Time: 10:07:35 PM
 */
public class DataObjectModel<T> extends LoadableDetachableModel {

    @SpringBean
    GenericDao genericDao;
    private Class<T> dataObjectClass;
    private Long id;

    @SuppressWarnings("unchecked")
    public DataObjectModel(Class<T> type, Long id) {
        InjectorHolder.getInjector().inject(this);
        this.id = id;
        // this sucks, I want to be able to create without passing this in
        dataObjectClass = type;
    }


    @Override
    protected Object load() {
         return genericDao.load(dataObjectClass, id);
    }

    @Override @SuppressWarnings("unchecked")
    public T getObject() {
        return (T) super.getObject();
    }

}
